<%@ taglib uri="/tags/struts-bean" prefix="bean"%>
<%@ taglib uri="/tags/struts-html" prefix="html"%>
<%@ taglib uri="/tags/struts-logic" prefix="logic"%>
<%@ taglib uri="/tags/core" prefix="c"%>
<%@ taglib uri="/tags/fmt" prefix="fmt"%>
<script type="text/javascript">

	function selectApplicationPeriod(field){
		var applicationFuturePeriodVersionId = document.getElementById("cornFuturesVersionsView.applicationFuturePeriodVersionId");
		applicationFuturePeriodVersionId.options[field.selectedIndex].selected = true;
	}
	function validate(){
        var errors = "";
        var reference = document.getElementById('cornFuturesVersionsView.reference').value;
        var quantity = document.getElementById('cornFuturesVersionsView.quantity').value;
        var unitPrice = document.getElementById('cornFuturesVersionsView.unitPrice').value;                                               
                
        if(reference == ""){                
        	errors = ' <bean:message key="lable.corn.error.input.reference"/>\n';			  
        }
		if(quantity == "" || parseInt( quantity ) == 0) {
        	errors += ' <bean:message key="lable.corn.error.input.quantity"/>\n';
        }      
        if(unitPrice == "" || parseInt( unloadAmount ) == 0) {
        	errors += ' <bean:message key="lable.corn.error.input.unitprice"/>\n';
        }if( errors == "" ){
            return true;
        }else{
            alert( '<bean:message key="label.common.errors"/> : \n' + errors );
			return false;
        }
	}
	function guardarNuevo(forma){
    	forma.saveandnew.value = 1;
    }
</script>
<html:form action="/cornFuturesVersionsEdit" onsubmit="return validate();" method="POST">
<input name="saveandnew" type="hidden" value="0"/>
<input type="hidden" id="versionId" name="versionId" value='<bean:write name="versionId"/>'>
<html:hidden property="cornFuturesVersionsView.cornFutureId" />
<br />
<table width="40%" cellpadding="2" cellspacing="1" border="0" bgcolor="#CCCCC0">
	<tr>
		<th colspan="2" align="center" class="titulocolumna"> <bean:message key="label.corn.futures.versions.table.title" /> </th>			 
	</tr>
	<tr>
		<td class="etiqueta" width="50%"><bean:message key="message.futurepurchase.periodaccount" /></td>
		<td class="etiqueta_campo" width="50%">
		<html:select property="cornFuturesVersionsView.accountFuturePeriodVersionId" styleClass="campo_texto" style="width:110px" onchange="selectApplicationPeriod(this);">
			<html:optionsCollection name="cornListFuturesVersions" value="futurePeriodVersionId" label="shortDescription" />
		</html:select>
		</td>

	</tr>
	<tr>
		<td class="etiqueta"><bean:message key="message.futurepurchase.periodapplication" /></td>
		<td class="etiqueta_campo" width="50%">
			<html:select property="cornFuturesVersionsView.applicationFuturePeriodVersionId" styleClass="campo_texto" style="width:110px">
				<html:optionsCollection name="cornListFuturesVersions" value="futurePeriodVersionId" label="shortDescription" />
			</html:select>
		</td>
	</tr>
	<tr>
		<td class="etiqueta" width="50%"><bean:message key="message.futurepurchase.reference" />:</td>
		<td class="etiqueta_campo" width="50%">
			<html:text styleClass="campo_texto" style="width:110px;" property="cornFuturesVersionsView.reference" styleId="reference" onclick="this.focus()"></html:text>
		</td>
	</tr>
	<tr>
		<td class="etiqueta" width="50%"><bean:message key="message.futurepurchase.contracts" />:</td>
		<td class="etiqueta_campo" width="50%">
			<html:text styleClass="columnanumero" property="cornFuturesVersionsView.quantity" style="width:110px" onkeydown="return (numeric(event,0) && noPaste(event, this));" onkeyup="extractNumber(this,2,false);" onclick="this.focus()" />
		</td>
	</tr>
	<tr>
		<td class="etiqueta" width="50%"><bean:message key="message.futurepurchase.price" />:</td>
		<td class="etiqueta_campo" width="50%">						
			<input type="text"  name="cornFuturesVersionsView.unitPrice" id="cornFuturesVersionsView.unitPrice"  value="<fmt:formatNumber maxFractionDigits="4" pattern="###,###,##0.0000" value="${CornFuturesVersionsForm.cornFuturesVersionsView.unitPrice}"/>" class="columnanumero"  onkeydown="return (numeric(event, 1) && noPaste(event, this));" onkeyup="extractNumber(this,4,false);" onfocus="this.select();"/>
		</td>
	</tr>
	<tr>
		<td class="etiqueta" width="50%"><bean:message key="message.futurepurchase.cornorigin"/>:</td>
		<td class="etiqueta_campo" width="50%">
			<html:select property="cornFuturesVersionsView.cornOrigin" styleClass="campo_texto" style="width:110px">
				<html:option value="I"><bean:message key="message.futurepurchase.cornorigin.imported"/></html:option>
				<html:option value="N"><bean:message key="message.futurepurchase.cornorigin.national"/></html:option>
			</html:select>
		</td>
	</tr>	
	
		
	<tr>
		<td colspan="2" align="center" class="columnadatoPar">
			<html:submit styleClass="boton"><bean:message key="label.common.save"/></html:submit>			
			&nbsp;&nbsp;&nbsp;&nbsp;<html:button styleClass="boton" property="backButton" onclick="location.href='cornFuturesVersionsQuery.do';"><bean:message key="label.common.cancel"/></html:button>
		</td>
	</tr>		
</table>
</html:form>
<script>
	cleanNumber(document.getElementById('cornFuturesVersionsView.quantity'));
	cleanNumber(document.getElementById('cornFuturesVersionsView.unitPrice'));
</script>
<br />